import 'package:cbec_app/components/common/dashed_line.dart';
import 'package:cbec_app/utils/Tools.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

///店铺装修-辅助分割
class DecorationWhiteLine extends StatefulWidget {
  ///辅助分割配置
  final Map<String, dynamic> info;
  const DecorationWhiteLine({super.key, required this.info});

  @override
  State<StatefulWidget> createState() {
    return _DecorationWhiteLineState();
  }
}

class _DecorationWhiteLineState extends State<DecorationWhiteLine> {
  @override
  Widget build(BuildContext context) {
    print('info ==== ${widget.info}');
    return getWidget();
  }

  //获取分割线组件
  Widget getWidget() {
    switch (widget.info['template_type']) {
      case 'line': //辅助线
        print('xxxxxxxxxxxxxx');
        final height = double.parse(widget.info['height'].toString());
        return Container(padding: EdgeInsets.only(left: getMargin(), right: getMargin()), height: height, child: getLine());
      case 'white':
      default:
        return Container(
          padding: EdgeInsets.only(left: getMargin(), right: getMargin()),
          width: double.infinity,
          height: double.parse(widget.info['height'].toString()),
        );
    }
  }

  ///获取分割线
  Widget getLine() {
    switch (widget.info['lineType']) {
      case 'solid': //实线
        print('实线 ==== ${widget.info['color']}');
        return Center(
          child: Container(
            height: 1,
            color: widget.info['color'] != null ? Tools.fromHex(widget.info['color']) : Colors.grey,
          ),
        );
      case 'dashed': //虚线
        print('xxxxxxxx ==== ${widget.info['color']}');
        return DashedLind(
          axis: Axis.horizontal,
          dashedWidth: 5,
          color: widget.info['color'] != null ? Tools.fromHex(widget.info['color']) : Colors.grey,
          count: 50,
        );
      case 'dotted': //点线
      default:
        return DashedLind(
          axis: Axis.horizontal,
          count: 80,
          color: widget.info['color'] != null ? Tools.fromHex(widget.info['color']) : Colors.grey,
        );
    }
  }

  ///获取margin
  double getMargin() {
    return (widget.info['hasPadding'] as int).toDouble();
  }
}
